//
// Created by wkm on 2023-12-04.
//

#include "memory.h"

void memory::prc_memory() {
    sc_lv<WORD_SIZE> allzs(SC_LOGIC_Z);
    sc_lv<WORD_SIZE> allxs(SC_LOGIC_X);

    if (en) {
        if (rw) {
            if (addr.read() < MEM_SIZE) {
                data = ram[addr.read()];
            } else {
                data = allxs;
#ifndef  SYNTHESIS
                cout << "Address" << addr << "is out of range for read operation." << endl;
#endif
            }
        } else {
            if (addr.read() < MEM_SIZE) {
                ram[addr.read()] = data;
            }
#ifndef SYNTHESIS
            else
                cout << "Address " << addr << " is out of range for write operation." << endl;
#endif
        }
    } else {
        data = allzs; // 把data赋值为全“Z”
    }
}